package com.ishuangmu.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ishuangmu.entity.Manager;
import com.ishuangmu.service.ManagerService;
import com.ishuangmu.util.CryptographyUtil;
import com.ishuangmu.util.ResponseUtil;
import net.sf.json.JSONObject;

/**
 * 管理员Controller类
 * @author Lin
 *
 */
@Controller
@RequestMapping("/manager2")
public class ManagerController {

	@Resource
	private ManagerService managerService;
	
	/**
	 * 用户登录
	 * @param blogger
	 * @param request
	 * @return
	 */
	@RequestMapping("/login")
	public String login(Manager manager,HttpServletResponse response)throws Exception{
		Subject subject=SecurityUtils.getSubject();
		UsernamePasswordToken token=new UsernamePasswordToken(manager.getUserName(), CryptographyUtil.md5(manager.getPassword(), "shuangmu"));
		JSONObject result=new JSONObject();
		try{
			subject.login(token); // 登录验证
			result.put("success", true);
		}catch(Exception e){
			result.put("success", false);
			result.put("errorInfo", "用户名或密码错误！");
			e.printStackTrace();
		}
		ResponseUtil.write(response, result);
		return null;
	}
	

}
